package com.javaGame.role;

import com.javaGame.frame.MainFrame;
import com.javaGame.util.ImageChange;
import com.javaGame.util.KeyPress;

import java.awt.*;

/**
 * 宠物貂
 */
public class Mink extends BaseRole{
    /**普通图片*/
    public static Image[] normalImg;
    /**准备吐火图片*/
    public static Image[] readyFireImg;
    /**吐火图片*/
    public static Image[] fireImg;
    /**状态*/
    private int status;
    /**普通状态常量*/
    public static final int  NORMAL = 0;
    /**准备吐火状态常量*/
    public static final int  READYFIRE = 1;
    /**吐火状态常量*/
    public static final int  FIRE = 2;
    /**聚气计数器*/
    private int count;
    /**图片切换对象*/
    private ImageChange imageChange = new ImageChange(3);
    /**吐火计数器*/
    private int fireCount;
    /**火对象*/
    private Fire fire;

    public Mink() {
        super(0, 0, 50, 30);
    }

    public Fire getFire() {
        return fire;
    }

    @Override
    public void move() {
        if(this.status == NORMAL){//普通状态
            this.setNormal();
        }
        else if(this.status == READYFIRE){//准备吐火
            this.setReadyFire();
        }
        else if(this.status == FIRE){//吐火
            this.setFire();
        }
        this.setImage();//设置图片
    }

    /**
     * 设置图片
     */
    private void setImage() {
        if(this.status == NORMAL){
            this.currentImg = imageChange.change(normalImg);
        }
        else if(this.status == READYFIRE){
            this.currentImg = imageChange.change(readyFireImg);
        }
        else if(this.status == FIRE){
            this.currentImg = imageChange.change(fireImg);
        }
    }

    /**
     * 吐火
     */
    private void setFire() {
        fireCount++;
        if(fireCount >= 200){
            fireCount = 0;
            //从角色集合中移除火对象
            MainFrame.roleList.remove(this.fire);
            this.fire = null;
            //回到普通状态
            this.status = NORMAL;
            this.width = 50;
            this.height = 30;
            this.count = 0;
        }
    }

    /**
     * 吐火初始化
     */
    public void fireInit(){
        this.count = 0;
        if(this.status == READYFIRE){
            this.status = FIRE;
            this.width = 120;
            this.height = 80;

            this.fire = new Fire();
            MainFrame.roleList.add(this.fire);
        }
    }
    /**
     * 准备吐火
     */
    private void setReadyFire() {
        this.x = MainFrame.girl.x + 50;
        this.y = MainFrame.girl.y - 80;
    }

    /**
     * 普通状态
     */
    private void setNormal() {
        this.x = MainFrame.girl.x - 20;
        this.y = MainFrame.girl.y - 20;

        if(KeyPress.isFire == true){
            count ++;

            if(count >= 50){
                this.status = READYFIRE;
                this.width = 100;
                this.height = 100;
            }
        }
    }
}
